package com.study.concurrentprogramming.monitor;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

/**
 * @Description : test
 * @Author : guxuemin
 * @Version : V1.0.0
 * @Date : 2021/7/28 21:56
 */
public class Test {
    String str = "";
    private int a = 0;



    public void say() {
        Thread thread1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
            System.out.println("t1:" + a);
            a = 8;
            System.out.println("t1:" + a);
        }, "t1");
        Thread thread2 = new Thread(() -> {
            System.out.println("t2:" +a);
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println("t2:" +a);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
        }, "t2");
        thread2.start();
        thread1.start();
    }

    public static void main(String[] args) throws InterruptedException {
        Test test = new Test();
        test.say();
        TimeUnit.SECONDS.sleep(8);
    }
}
